<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:a4j="http://richfaces.org/a4j"
	xmlns:rich="http://richfaces.org/rich"
	template="../template/template.xhtml">

	<ui:define name="body">
		<f:view>
			<h:form>
				<rich:panel>
					<f:facet name="header">
						<h:outputText value="Lista de Artefatos" />
					</f:facet>
					
					<!-- filtros -->
					<rich:toolBar height="34" itemSeparator="line">
						<rich:toolBarGroup>
							<h:outputLabel value="Nome:" />
							<h:inputText id="nome" value="#{artefatoController.artefato.nome}"/>	
						</rich:toolBarGroup>
		
						<rich:toolBarGroup>
							<h:outputLabel value="Categoria:" />
							<h:selectOneMenu id="categoria" value="#{artefatoController.artefato.categoria.categoriaId}" immediate="true">
								<f:selectItems value="#{artefatoController.allCategorias}" />
							</h:selectOneMenu>
						</rich:toolBarGroup>
						
						<rich:toolBarGroup>
							<h:outputLabel value="Projeto:" />
							<h:selectOneMenu id="projeto" value="#{artefatoController.artefato.projeto.projetoId}" immediate="true">
								<f:selectItems value="#{artefatoController.allProjetos}" />
							</h:selectOneMenu>
						</rich:toolBarGroup>
						
						<rich:toolBarGroup location="right" style="width:180px;">
							<h:commandButton value="Consultar" action="#{artefatoController.consultarArtefatos}" />
						</rich:toolBarGroup>
					</rich:toolBar>
		
					<br/>
							
					<!-- lista -->
					<rich:dataTable value="#{artefatoController.artefatos}" binding="#{artefatoController.dataTable}" var="artefato" width="100%">
						<rich:column width="30%">
							<f:facet name="header">
								<h:outputLabel value="Nome" />
							</f:facet>
							<h:outputText value="#{artefato.nome}" />
						</rich:column>
					
						<rich:column width="20%">
							<f:facet name="header">
								<h:outputLabel value="Categoria" />
							</f:facet>
							<h:outputText value="#{artefato.categoria.nome}" />
						</rich:column>
			
						<rich:column width="20%">
							<f:facet name="header">
								<h:outputLabel value="Projeto" />
							</f:facet>
							<h:outputText value="#{artefato.projeto.nome}" />
						</rich:column>
						
						<rich:column width="5%">
							<f:facet name="header">
								<h:outputLabel value="Restrito" />
							</f:facet>
							<center>
				            	<h:graphicImage url="/image/tick.png" rendered="#{artefato.restrito}"/>
				            </center>	
						</rich:column>
						
						<rich:column width="15%">
							<f:facet name="header">
								<h:outputLabel value="Acoes" />
							</f:facet>
							<center>
								<a4j:commandButton value="Editar" action="#{artefatoController.editar}" />
								<a4j:commandButton value="Remover" action="#{artefatoController.consultaDependencias}" reRender="removerArtefatoPanel" oncomplete="javascript:Richfaces.showModalPanel('removerArtefato');" />
							</center>	
						</rich:column>
					</rich:dataTable>
					
					<br/>
		            
		        	<div align="center" style="width: 100%;"><h:outputText id="message" style="color: red;" value="#{artefatoController.message}"/></div>
		            
		        	<br/>				
					
				</rich:panel>
			</h:form>
			
			<!-- modal remover artefato -->
			<rich:modalPanel styleClass="richModal" id="removerArtefato" zindex="2000" width="550" height="350">
				<f:facet name="header">
					<h:outputText value="Remover Artefato" />
				</f:facet>
				<h:panelGrid id="removerArtefatoPanel" width="100%">
					<h:form id="form2">
						<rich:dataTable value="#{artefatoController.dependentes}" var="artefatoRelacionado" width="100%">
							<rich:column>
								<f:facet name="header">
									<h:outputLabel value="Nome" />
								</f:facet>
								<h:outputText value="#{artefatoRelacionado.nome}" />
							</rich:column>
						
							<rich:column>
								<f:facet name="header">
									<h:outputLabel value="Categoria" />
								</f:facet>
								<h:outputText value="#{artefatoRelacionado.categoria.nome}" />
							</rich:column>
				
							<rich:column>
								<f:facet name="header">
									<h:outputLabel value="Projeto" />
								</f:facet>
								<h:outputText value="#{artefatoRelacionado.projeto.nome}" />
							</rich:column>
						</rich:dataTable>

						<br />
						
						<rich:separator height="1"/>

						<br />

						<div align="center" style="width: 100%;">		
							<h:commandButton styleClass="button-input" value="Remover" action="#{artefatoController.removerArtefato}" />
							<a4j:commandButton styleClass="button-input" value="Cancelar" onclick="Richfaces.hideModalPanel('removerArtefato')" />
						</div>	
					</h:form>
				</h:panelGrid>
			</rich:modalPanel>
			
		</f:view>
	</ui:define>

</ui:composition>
